<template>
  <el-dialog :title="title" :close-on-click-modal="false" :fullscreen="true" :visible.sync="visible"
    :before-close="cancel" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="50%">
    <el-row class="JNPF-common-search-box" :gutter="16">
      <el-form @submit.native.prevent ref="elForm" :model="dataForm" :rules="rules">

        <el-col :span="8">
            <el-form-item  label="类型编号" prop="fdictno">
                <el-input v-model="dataForm.fdictno" />
            </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item label="设备编码" prop="fnumpre">
                <el-input v-model="dataForm.fnumpre" />
            </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item label="设备类别">
            <el-select v-model="dataForm.ftypename" placeholder="请选择">
                <el-option
                v-for="item in options1"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item  label="类型名称" prop="fdictname">
                <el-input v-model="dataForm.fdictname" />
            </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item label="红外码库" prop="fredcode">
                <el-input v-model="dataForm.fredcode" />
            </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item label="插脚数量" prop="fmarkNum">
                <el-input v-model="dataForm.fmarkNum" />
            </el-form-item>
        </el-col>
        
        <el-col :span="8">
            <el-form-item label="设备图片" prop="ficon2" width="120px">
              <el-upload
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload">
                <img style="width: 280px; height: 80px"
                     v-if="imageUrl1" :src="imageUrl1" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item  label="备注信息" prop="fmemo">
                <el-input v-model="dataForm.fmemo" />
            </el-form-item>
        </el-col>

        <el-col :span="5">
          <el-form-item label="">
            <!-- <el-button type="success" icon="el-icon-plus" @click="insert">添加场地</el-button> -->
            <el-button type="primary" :loading="loading">返回</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>

    <el-table :data="list" border stripe>
      <el-table-column label="操作" width="80">
        <template slot-scope="scope">
          <el-button slot="reference" icon="el-icon-delete" style="color: red" @click="shopdate(scope.$index)"
            type="text">删除</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="fentryid" label="序号" ></el-table-column>
      <el-table-column prop="faction" label="控制指令" ></el-table-column>
      <el-table-column prop="fdescribe" label="指令描述"></el-table-column>
      <el-table-column prop="sceneFlag" label="场景显示" ></el-table-column>
      <el-table-column align="center" label="图片" prop="fscoreFlag"></el-table-column>
    </el-table>
    <div class="addbox">
        <el-link icon="el-icon-plus" type="primary" >添加一行</el-link>
    </div>
    <StudqueryFcuston ref="StudqueryFcuston" @confirm="shoplist" />
  </el-dialog>
</template>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<script>
  import StudqueryFcuston from "@/components/StudqueryFcuston/StudqueryFcuston.vue"
  import jnpf from "@/utils/jnpf"
  export default {
    components: { StudqueryFcuston },
    props: {
      formationlist: {
        type: Array,
        default: [],
      },
    },
    data() {
      return {
        imageUrl1:require('@/assets/images/me/equipment.png'),
        title: "查看详情",
        insertorupdate: true,
        dataForm: {
          fdictno: 5,
          fdictname: "空调",
          fredcode: undefined,
          ftypename: "设备",
          fmarkNum: 2,
          ficon: undefined,
          id: 1,
          ficon2: undefined,
          fnumpre: "SK",
        },
        rules: {
        },
        list:[{ "fentryid":1,
                "faction": "ON",
                "fdescribe": "开",
                "sceneFlag": "是",
                "fscoreFlag":""
                },
              {"fentryid":2,
                "faction": "OFF",
                "fdescribe": "关",
                "sceneFlag": "是",
                "fscoreFlag":""
                }],
        loading: false,
        visible: false,

        options1: [
                    { id: "0", name: "排插" },
                    { id: "1", name: "设备" }
                ],
        
      };
    },
    created() {
    },
    mounted() { },
    methods: {
      //
      init(FBILLNO) {
        this.dataForm.FBILLNO = FBILLNO;
        if (this.dataForm.FBILLNO) {
          this.title = "修改"
          this.insertorupdate = false;
        }
        else {
          this.title = "新增"
          this.dataForm.FBILLNO = "K" + Math.floor(Math.random() * 10000000) + 1;
          this.insertorupdate = true;
        }
        this.visible = true;
      },
      insert() {
        this.$refs.StudqueryFcuston.open();
      },
      shoplist(data) {
        data.forEach(item => {
          this.list.push({
            FBILLNO: this.dataForm.FBILLNO
            , FENTRYID: "1"
            , FYEAR: 2024
            , FGRADE: "大一"
            , FCLASS: "化学系1班"
            , FSTUDNAME: "曹操"
          },{
            FBILLNO: this.dataForm.FBILLNO
            , FENTRYID: "2"
            , FYEAR: 2024
            , FGRADE: "大一"
            , FCLASS: "化学系1班"
            , FSTUDNAME: "刘备"
          })
        });
      },
      //
      cancel() {
        this.$refs.elForm.resetFields();
        this.list = [];
        this.visible = false;
      },

      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },

    },
  };
</script>